/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.soa.service.busi.wx;

import com.lianzt.commondata.AbstractCommonData;
import com.lianzt.commondata.DataConvertFactory;
import com.soa.exception.GlobalException;
import com.soa.service.BaseService;
import com.soa.util.SystemUtil;
import com.soa.util.tccgl.WeixinUtil;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 *  工地用车登记
 *  P90006
 * @author chang
 */
@Service
public class YcdjService extends BaseService{
    private final Logger log = LoggerFactory.getLogger(YcdjService.class);
    
    @Resource
    private WeixinUtil wx;
    @Override
    public String[] keys() {
        return null;
    }

    @Override
    public void execute(AbstractCommonData in, AbstractCommonData inhead, AbstractCommonData out, AbstractCommonData outhead) {
        String dyc = in.getStringValue("dyc");
        String ycr = in.getStringValue("ycr");
        String ycsj_ks = in.getStringValue("ycsj_ks");
        String ycsj_js = in.getStringValue("ycsj_js");
        ycsj_ks = ycsj_ks.replace("T", " ");
        ycsj_js = ycsj_js.replace("T", " ");
        String yt = in.getStringValue("yt");
        //获取session
        AbstractCommonData sess = getSession(in);
        String userid = sess.getStringValue("userid");
        String id = SystemUtil.getSerialNum();
        try {
            update("insert_jz_gdyc", new Object[]{id,dyc,ycsj_ks,ycsj_js,ycr,yt,userid});
        } catch (Exception e) {
            log.error("保存用车登记信息出错！", e);
            throw new GlobalException(9000601, e);
        }
        String yt_ = yt==null?"无":yt;
        //企业号给用户发送消息
        String context="【系统提醒】\n"
                +"用车登记成功！\n"
                + "用车人:"+ycr+"\n"
                + "要用车辆:"+SystemUtil.getColValueDesc("jz_gdyc.cph", dyc)+"\n"
                + "用车时间(始):"+ycsj_ks+"\n"
                +"用车时间(终):"+ycsj_js+"\n"
                +"用途:"+yt_;
        try {
            String code = wx.sendMessage(userid, "", "", "text", 13, context);
            AbstractCommonData abs= DataConvertFactory.getInstanceByJson(code);
            log.debug("调用企业号发送信息返回:{}"+abs);
            if("ok".equals(abs.getStringValue("errmsg"))){
                log.debug("----------------------企业号发送消息成功!");
            }
        } catch (Exception e) {
            log.error("企业号发送消息失败!", e);
        }
        
        
                
    }
    
}
